package com.atqh.logistics.service.impl;


import com.atqh.logistics.domin.Driver;
import com.atqh.logistics.utils.Result;
import com.atqh.logistics.utils.Vo.params.RequestParam;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.atqh.logistics.domin.Requests;
import com.atqh.logistics.service.RequestsService;
import com.atqh.logistics.mapper.RequestsMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 *
 */
@Service
public class RequestsServiceImpl extends ServiceImpl<RequestsMapper, Requests>
        implements RequestsService {

    @Autowired
    private RequestsMapper requestsMapper;


    @Override
    public Result Request(RequestParam requestParam, HttpServletRequest req) {
        Requests requests = new Requests();
        BeanUtils.copyProperties(requestParam, requests);
        Driver driver = (Driver) req.getSession().getAttribute("driver");
        requests.setDriverId(driver.getId());
        requestsMapper.insert(requests);
        return Result.success(null);
    }

    @Override
    public Result ControllerRequest(int reqId, int flag) {
        LambdaQueryWrapper<Requests> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Requests::getId, reqId);
        Requests requests = new Requests();
        requests.setFlag(flag);
        requestsMapper.update(requests, queryWrapper);
        return Result.success(null);
    }

    @Override
    public Result SelectDaiReq() {

        List<Requests> list = requestsMapper.selectDaiReq();
        return null;
    }

    @Override
    public Result ViewOwnRequest(HttpServletRequest req) {
        LambdaQueryWrapper<Requests> queryWrapper = new LambdaQueryWrapper<>();
        Driver driver1 = (Driver) req.getSession().getAttribute("driver");
        queryWrapper.eq(Requests::getDriverId, driver1.getId());
        List<Requests> requests = requestsMapper.selectList(queryWrapper);
        return Result.success(requests);
    }
}




